import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:grint/constant/colors.dart';
import 'package:grint/utils/whisper.dart';
import 'package:grint/widget/my_text.dart';

enum JubaoLeixing {
  pornographicVulgarity,
  hateSpeech,
  nauseating,
  illegal,
  spam,
  other,
  block,
}

class FankuiTanchuang extends StatefulWidget {
  final String? mubiaoyonghuId;
  final String? mubiaoNeirongId;
  final Function(JubaoLeixing jubaoType, String? fujiaxinxi)? onJubao;

  const FankuiTanchuang({
    super.key,
    this.mubiaoyonghuId,
    this.mubiaoNeirongId,
    this.onJubao,
  });

  @override
  State<FankuiTanchuang> createState() => _FankuiTanchuangState();
}

class _FankuiTanchuangState extends State<FankuiTanchuang> {
  String _huoquJubaoLeixingWenzi(JubaoLeixing leixing) {
    switch (leixing) {
      case JubaoLeixing.pornographicVulgarity:
        return 'Sexually Explicit Material';
      case JubaoLeixing.hateSpeech:
        return 'Hate Speech';
      case JubaoLeixing.nauseating:
        return 'Nauseating Content';
      case JubaoLeixing.illegal:
        return 'Illegal Content';
      case JubaoLeixing.spam:
        return 'Spam';
      case JubaoLeixing.other:
        return 'Something else';
      case JubaoLeixing.block:
        return 'Block User';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        width: 320.w,
        decoration: BoxDecoration(
          color: AppColors.white,
          borderRadius: BorderRadius.circular(20.r),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              padding: EdgeInsets.all(20.w),
              decoration: BoxDecoration(
                color: AppColors.lightBlue.withValues(alpha: 0.1),
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20.r),
                  topRight: Radius.circular(20.r),
                ),
              ),
              child: Row(
                children: [
                  Expanded(
                    child: MyText(
                      text: 'Report',
                      type: TextType.rubik,
                      fontSize: 18.sp,
                      fontWeight: FontWeight.bold,
                      color: AppColors.black,
                    ),
                  ),
                  GestureDetector(
                    onTap: () => Navigator.of(context).pop(),
                    child: Icon(
                      Icons.close,
                      size: 24.sp,
                      color: AppColors.textGrey,
                    ),
                  ),
                ],
              ),
            ),

            // 内容区域
            Container(
              padding: EdgeInsets.all(20.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  ...JubaoLeixing.values.map(
                    (leixing) => _goujianJianhuaJubaoXuanxiang(leixing),
                  ),

                  // 取消按钮
                  SizedBox(height: 8.h),
                  _goujianQuxiaoAnniu(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _goujianJianhuaJubaoXuanxiang(JubaoLeixing leixing) {
    return GestureDetector(
      onTap: () {
        // 直接举报，不需要选择状态
        _zhijieJubao(leixing);
      },
      child: Container(
        margin: EdgeInsets.only(bottom: 12.h),
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.h),
        decoration: BoxDecoration(
          color: AppColors.white,
          borderRadius: BorderRadius.circular(8.r),
          border: Border.all(
            color: AppColors.border.withValues(alpha: 0.3),
            width: 1.w,
          ),
        ),
        child: Row(
          children: [
            Expanded(
              child: MyText(
                text: _huoquJubaoLeixingWenzi(leixing),
                type: TextType.miSans,
                fontSize: 15.sp,
                fontWeight: FontWeight.w500,
                color: AppColors.black,
              ),
            ),
            Icon(
              Icons.arrow_forward_ios,
              size: 14.sp,
              color: AppColors.textGrey,
            ),
          ],
        ),
      ),
    );
  }

  void _zhijieJubao(JubaoLeixing jubaoLeixing) {
    widget.onJubao?.call(jubaoLeixing, null);
    Navigator.of(context).pop();

    Whisper.murmur('Report submitted successfully');
  }

  Widget _goujianQuxiaoAnniu() {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).pop();
      },
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.h),
        decoration: BoxDecoration(
          color: AppColors.textGrey.withValues(alpha: 0.1),
          borderRadius: BorderRadius.circular(8.r),
          border: Border.all(
            color: AppColors.border.withValues(alpha: 0.3),
            width: 1.w,
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MyText(
              text: 'Cancel',
              type: TextType.miSans,
              fontSize: 15.sp,
              fontWeight: FontWeight.w500,
              color: AppColors.textGrey,
            ),
          ],
        ),
      ),
    );
  }
}

class FankuiTanchuangBangzhu {
  static void xianshi(
    BuildContext context, {
    String? mubiaoyonghuId,
    String? mubiaoNeirongId,
    Function(JubaoLeixing jubaoType, String? fujiaxinxi)? onJubao,
  }) {
    showDialog(
      context: context,
      barrierDismissible: true,
      builder:
          (context) => FankuiTanchuang(
            mubiaoyonghuId: mubiaoyonghuId,
            mubiaoNeirongId: mubiaoNeirongId,
            onJubao: onJubao,
          ),
    );
  }
}
